/*
*  This file is part of mangusta
*
*  mangusta is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  mangusta is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with mangusta; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  US
*
*  Author: <antonino.calderone@ericsson.com>, <acaldmail@gmail.com>
*
*/


// ----------------------------------------------------------------------------

#ifndef __NU_LABEL_TBL_H__
#define __NU_LABEL_TBL_H__


// ----------------------------------------------------------------------------

#include "nu_variant.h"
#include "nu_exception.h"
#include "nu_symbol_map.h"

#include <string>
#include <algorithm>
#include <mutex>


// ----------------------------------------------------------------------------

namespace nu
{

using label_t = unsigned int;


// ------------------------------------------------------------------------

class label_tbl_t : public symbol_map_t < std::string, label_t >
{
private:
   using super_t = symbol_map_t < std::string, label_t > ;
   mutable std::mutex _mtx;

public:
   label_tbl_t(const label_tbl_t&) = delete;
   label_tbl_t& operator=(const label_tbl_t&) = delete;

   void clear()
   {
      std::lock_guard<std::mutex> _lock(_mtx);

      super_t::clear();
   }

   label_t & operator [] (const std::string& key)
   {
      std::lock_guard<std::mutex> _lock(_mtx);

      return super_t::operator[](key);
   }


   const label_t& operator [] (const std::string& key) const
   {
      std::lock_guard<std::mutex> _lock(_mtx);

      return super_t::operator[](key);
   }


   label_tbl_t() = default;

protected:
   virtual void get_err_msg(const std::string& key, std::string& err) const;

};


// ------------------------------------------------------------------------

}


// ----------------------------------------------------------------------------

#endif //__NU_LABEL_TBL_H__
